package baiduClub.schedule;

import java.util.Calendar;


public class CalculateDate {
	
	private String dayOfWeekString;
	private int week;
	
	public String calculateDayOfWeek(int dayOfWeekInt)
	{
		switch (dayOfWeekInt) {
		case 1:
			this.dayOfWeekString = "星期日";
			break;
	    
		case 2:
			this.dayOfWeekString = "星期一";
			break;
			
		case 3:
			this.dayOfWeekString = "星期二";
			break;
			
		case 4:
			this.dayOfWeekString = "星期三";
            break;
            
		case 5:
			this.dayOfWeekString = "星期四";
			break;
			
		case 6:
			this.dayOfWeekString = "星期五";
			break;
		
		case 7:
			this.dayOfWeekString = "星期六";
			break;
		default:
			break;
		}
		
		return dayOfWeekString;
	}
	
	public int calculateWeek(Calendar a,Calendar b)
	{
		int dayOfYearOfFirstDay = a.get(Calendar.DAY_OF_YEAR);
		int dayOfYearOfNow = b.get(Calendar.DAY_OF_YEAR);
		int dayOfWeekFirst = a.get(Calendar.DAY_OF_WEEK);
		
		int theLastDayOfYear = a.getMaximum(Calendar.DAY_OF_YEAR);
		
		if(a.get(Calendar.YEAR)==b.get(Calendar.YEAR))
		{
			week = (dayOfYearOfNow - dayOfYearOfFirstDay + dayOfWeekFirst - 1) / 7 + 1; 
		}
		else 
		{
			week = (dayOfYearOfNow + theLastDayOfYear - dayOfYearOfFirstDay + dayOfWeekFirst - 1) / 7 + 1;
		}
		
		return week;
	}

}
